package be.castanea.client.model;

import java.io.Serializable;

/**
 * Castanea
 * 2009
 * @author Geert van Leemputten, Steven Rymenans, Bart Van Hooydonck
 */
public class Movement implements Serializable {

    private int forwardSpeed;
    private int sidewaySpeed;
    private int turnSpeed;

    public Movement() {
    }

    public Movement(int forwardSpeed, int sidewaySpeed, int turnSpeed) {
        this.forwardSpeed = forwardSpeed;
        this.sidewaySpeed = sidewaySpeed;
        this.turnSpeed = turnSpeed;
    }

    public Movement(int[] speeds) {
        this.forwardSpeed = speeds[0];
        this.sidewaySpeed = speeds[1];
        this.turnSpeed = speeds[2];
    }

    public int getForwardSpeed() {
        return forwardSpeed;
    }

    public void addForward(int forwardSpeed) {
        this.forwardSpeed += forwardSpeed;
    }

    public int getSidewaySpeed() {
        return sidewaySpeed;
    }

    public void addSideway(int sidewaySpeed) {
        this.sidewaySpeed += sidewaySpeed;
    }

    public int getTurnSpeed() {
        return turnSpeed;
    }

    public void addTurnSpeed(int turnSpeed) {
        this.turnSpeed += turnSpeed;
    }

    public int[] toArray() {
        return new int[]{forwardSpeed, sidewaySpeed, turnSpeed};
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Movement other = (Movement) obj;
        if (this.forwardSpeed != other.forwardSpeed) {
            return false;
        }
        if (this.sidewaySpeed != other.sidewaySpeed) {
            return false;
        }
        if (this.turnSpeed != other.turnSpeed) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + this.forwardSpeed;
        hash = 59 * hash + this.sidewaySpeed;
        hash = 59 * hash + this.turnSpeed;
        return hash;
    }
}
